package demo2;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-08
 * Time: 10:38
 */
public class TestDemo1 {

    public static void main(String[] args) throws IOException {
        //打开文件
        InputStream inputStream = new FileInputStream("text.txt");
//        while(true){
//            int b = inputStream.read();
//            if(b==-1){
//                break;
//            }
//            System.out.println(b);
//        }
//        byte[] bytes = new byte[1024];
//        int len = inputStream.read(bytes);
//        //int l =inputStream.read(bytes,1,5);
//        for(int i =0;i<len;++i){
//            System.out.print(bytes[i]+" ");
//        }
        //打印中文
        byte[] bytes = new byte[1024];
        int len = inputStream.read(bytes);
        String s = new String(bytes,0,len,"utf8");
        System.out.println(s);
        inputStream.close();//关闭文件
    }

}
